<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 * @version		$Id:$
 */

$this->headTitle($this->TRANSLATOR->translator('category_edit_page_title') . ' - ' . $this->TRANSLATOR->translator('common_admin_title', 'core'));
?>
<div class="content">
	<div class="box header mb0">
		<div class="head"><div></div></div>
		<h2 class="g_a_breadcump">
			<a class="fl" href="<?php echo $this->url('core_dashboard_index'); ?>"><?php echo $this->TRANSLATOR->translator('dashboard_breadcump', 'core'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="<?php echo $this->url('category_category_list'); ?>"><?php echo $this->TRANSLATOR->translator('category_breadcump'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="javascript: void(0);"><?php echo $this->TRANSLATOR->translator('category_edit_breadcump'); ?></a>
			<div class="clear"></div>
		</h2>
	</div>
</div>
<div class="content">
	<div class="desc">
		<div class="body">
			<!--  -->
			<form action="<?php echo $this->url('category_category_edit', $this->categoryData); ?>" method="post" id="gCategoryCategoryEdit">
				<h4 class="g_a_h4 fl"><?php echo $this->TRANSLATOR->translator('category_edit_guide'); ?></h4>
				<div class="fr">
					<?php if ($this->ACL->isAllowed('add', 'category', 'category')) : ?>
					<a class="fl g_a_tip form_submit g_a_submit_button mr5" href="javascript: void(0);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('category_button_save_title')); ?>"></a>
					<?php endif; ?>
					<a class="fl g_a_tip g_a_cancel_button mr5" href="javascript: history.go(-1);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_back_button', 'core')); ?>"></a>
					<?php if ($this->ACL->isAllowed('list', 'category', 'category')) : ?>
					<a class="fl g_a_tip" href="<?php echo $this->url('category_category_list'); ?>" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('category_actions_list_title')); ?>">
						<img src="<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->APP_TEMPLATE; ?>/skins/<?php echo $this->APP_SKIN; ?>/images/actions_list_icon.png" style="padding: 0 5px 0 0;" />
					</a>
					<?php endif; ?>
					<?php if ($this->ACL->isAllowed('add', 'category')) : ?>
					<a class="fl g_a_tip" href="<?php echo $this->url('category_category_add'); ?>" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('category_actions_add_title')); ?>">
						<img src="<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->APP_TEMPLATE; ?>/skins/<?php echo $this->APP_SKIN; ?>/images/actions_add_icon.png" style="padding: 0 5px 0 0;" />
					</a>
					<?php endif; ?>
				</div>
				<div class="g_a_line"></div>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('category_name'); ?></label>
					<input title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('category_name_description')); ?>" type="text" class="text w_20 g_a_tip_right" name="category[name]" id="name" value="<?php if (isset($this->categoryData['name'])) : ?><?php echo $this->categoryData['name']; ?><?php endif; ?>" />
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['name'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['name']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('category_slug'); ?></label>
					<input title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('category_slug_description')); ?>" type="text" class="text w_20 g_a_tip_right" name="category[slug]" id="slug" value="<?php if (isset($this->categoryData['slug'])) : ?><?php echo $this->categoryData['slug']; ?><?php endif; ?>" />
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['slug'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['slug']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('category_meta'); ?></label>
					<textarea cols="90" rows="10" name="category[meta]" id="meta"><?php if (isset($this->categoryData['meta'])) : ?><?php echo $this->categoryData['meta']; ?><?php endif; ?></textarea>
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['meta'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['meta']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('category_module'); ?></label>
					<?php echo Modules_Core_Services_Module::moduleSelect(array(
																		'name' => 'category[module_id]', 
																		'id' => 'module_id', 
																		'selected' =>  $this->categoryData['module_id'],
																		'disabled' => true)); ?>
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['module_id'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['module_id']); ?></span>
					<?php endif; ?>					
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('category_language'); ?></label>
					<?php echo Modules_Core_Services_Language::languageSelect(array(
																			'name' => 'category[language]',
																			'id' => 'languageSelector', 
																			'selected' => $this->categoryData['language'],
																			'disabled' => $this->categoryData['language'] == $this->APP_LANG)); ?>
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['language'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['language']); ?></span>
					<?php endif; ?>						
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('category_source_item'); ?></label>
					<div class="g_a_translatable">
						<?php echo Modules_Category_Services_Category::translatableCategory(array(
																						'name' => 'category[source_item]', 
																						'id' => 'category_source_item',
																						'selected' => (null == $this->sourceCategory) ? null : $this->sourceCategory['category_id'],
																						'disabled' => null,
																					), $this->categoryData['language'], $this->categoryData['module_id']); ?>
						</div>					
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('category_parent'); ?></label>
					<div class="g_a_translatable">
						<?php echo Modules_Category_Services_Category::categorySelect(array(
																					'name' => 'category[parent_id]', 
																					'id' => 'category_parent_id', 
																					'selected' => $this->categoryData['parent_id'],
																					'disabled' => $this->categoryData['category_id']), $this->categoryData['language'],  $this->categoryData['module_id']); ?>
						</div>					
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('category_status'); ?></label>
					<select class="g_a_tip_right" id="status" name="category[status]" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('category_status_description')); ?>">
						<option value="inactive"<?php if (isset($this->categoryData) && $this->categoryData['status'] == 'inactive') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('category_status_inactive'); ?></option>
						<option value="active"<?php if (isset($this->categoryData) && $this->categoryData['status'] == 'active') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('category_status_active'); ?></option>
					</select>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				
				<p class="last buttons_demo">
					<?php if ($this->ACL->isAllowed('add', 'category', 'category')) : ?>
					<a class="button form_submit green" href="<?php echo $this->url('category_category_edit'); ?>"><small class="icon check"></small><span><?php echo $this->TRANSLATOR->translator('common_submit_button', 'core'); ?></span></a>
					<?php endif; ?>
					<a class="button red" href="javascript: history.go(-1);"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('common_back_button', 'core'); ?></span></a>
					<?php if (isset($this->tokenElement)) : ?><?php echo $this->tokenElement; ?><?php endif; ?>
				</p>
			</form>
			<!--  -->
			<div class="clear"></div>
		</div>
	</div>
	<div class="body_footer">
		<div class="bottom_left"><div class="bottom_right"></div></div>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
	<?php if (($string = $this->MESSENGER->printMessages()) != null) : ?>
	Gio.Message.success('<?php echo $string; ?>');
	<?php endif; ?>
	$('#name').change(function() {
		var slug = Gio.Util.generateSlug($(this).val());
		$('#slug').val(slug);
	});

	$('#module_id').change(function() {
		/**
		 * Source Item
		 */
		var containerSource = $('#category_source_item').parents('.g_a_translatable');
		$(containerSource).addClass('g_a_ajax_loading');
		var moduleId = $(this).val();
		var dataSource    = { 
				id: 'category_source_item', 
				name: $('#category_source_item').attr('name'), 
				language: '<?php echo $this->APP_LANG; ?>', 
				moduleId: moduleId,
				viewHelperClass: $('#category_source_item').attr('viewHelperClass'), 
				viewHelperAttributes: $('#category_source_item').attr('viewHelperAttributes') 
			};
		$.ajaxq('category_source', {
			type: 'post',
			url: '<?php echo $this->url('core_locale_viewhelper'); ?>',
			data: dataSource,
			success: function(response) {
				$(containerSource).html(response).removeClass('g_a_ajax_loading');
			}
		});
		 
		/**
		 * Item
		 */
		var containerItem = $('#category_parent_id').parents('.g_a_translatable');
		$(containerItem).addClass('g_a_ajax_loading');
		var lang = $('#languageSelector').val();
		var moduleId = $(this).val();
		var data    = { 
				id: 'category_parent_id', 
				name: $('#category_parent_id').attr('name'), 
				language: lang, 
				moduleId: moduleId,
				viewHelperClass: $('#category_parent_id').attr('viewHelperClass'), 
				viewHelperAttributes: $('#category_parent_id').attr('viewHelperAttributes') 
			};
		$.ajaxq('category_module', {
			type: 'post',
			url: '<?php echo $this->url('core_locale_viewhelper'); ?>',
			data: data,
			success: function(response) {
				$(containerItem).html(response).removeClass('g_a_ajax_loading');
			}
		});
	});
});
</script>